package com.kqb.autoconfigure;

import com.kqb.config.TokenWebMvcConfig;
import com.kqb.token.TokenTemplate;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 杉果树皮
 * @date 2025/2/12 19:46
 * @description:
 */
@AutoConfiguration
@EnableConfigurationProperties(TokenInterceptorProperties.class)
@ConditionalOnProperty(prefix = "token.interceptor", name = "enable", matchIfMissing = true)
@ConditionalOnClass({WebMvcConfigurer.class, HandlerInterceptor.class, TokenTemplate.class})
public class TokenInterceptorAutoConfigure {


    @Bean
    @ConditionalOnMissingBean(TokenWebMvcConfig.class)
    public WebMvcConfigurer webMvcConfigurer(TokenTemplate tokenTemplate, TokenInterceptorProperties tokenInterceptorProperties) {
        TokenWebMvcConfig tokenWebMvcConfig = new TokenWebMvcConfig(tokenTemplate, tokenInterceptorProperties);
        return tokenWebMvcConfig;
    }


}
